<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
    <title>文档管理</title>
	<%@ include file="/common/header/meta.jsp"%>
	<%@ include file="/common/header/script.jsp"%>
    <script type="text/javascript">
    var $tree, $parent_box ;
    $(function(){
    	$parent_box = $("#pid").combotree({
			url : $.webapp.root + "/admin/site/column/combo_tree.do",
			idFiled:'pid', textFiled:'name', editable: false, required:false, lines:true, autoShowPanel: false
		}) ;
    	
		$tree = $("#tree").tree({
			url: $.webapp.root + "/admin/site/column/doNotNeedAuth_tree.do",
			method: "get", animate: true, idField: 'id',
			onClick: function(node){
				
				$dg = $("#dg").datagrid({
					url: $.webapp.root + "/admin/site/doc/doNotNeedAuth_datagrid.do?pid="+node.id,
					idField: 'id', fit: true, border: false, pageSize: 30, pageList: [30,40,50,100,200,1000	], rownumbers: true,
					remoteSort: true, toolbar: '#toolbars', striped:true, pagination: true, singleSelect: false,
					sortName: 'pushDate', sortOrder: 'asc',
					frozenColumns: [[
					    { field: 'ck', checkbox: true },
					    { field: 'id', title: 'ID', width: 80, hidden: true }
					]],
					columns: [[
					    //{ field: 'pageLogo', title: 'LOGO', width: 100, align: 'center' },
					    { field: 'pageTitle', title: '文章标题', width: 300 },
					    //{ field: 'contentAttr', title: '文章属性', width: 100 },
					    { field: 'isPush', title: '发布状态', width: 60, sortable: true, align: 'center', formatter:function(value,row){
					    	var str1 = $.string.format("<a href='javascript:push(\"{0}\")'><font color='red'>未发</font></a>", row.id);
					    	var str2 = $.string.format("<a href='javascript:push(\"{0}\")'><font color='#00CC00'>已发</font></a>", row.id);
					    	
					    	if(value == 0){return str1;}
					    	else if(value == 1){return str2;}
					    }},
					    { field: 'pushDate', title: '发布日期', width: 140 },
					    { field: 'created', title: '创建时间', width: 140 }
		 			    //{ field: 'createName', title: '创建者', width: 140 },
		 			    //{ field: 'modifyDate', title: '最后修改时间', width: 140 },
		 			    //{ field: 'modifyName', title: '修改者', width: 140 }
					]],
					onLoadSuccess: function(node, data) {
						$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
						$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');
					}
				}) ;
				
				
		    }
		});    
    });
    
    
    function form_edit(form) {
    	if("E" == form) {
			var node = $dg.datagrid('getSelected');
			var nodetree = $tree.tree('getSelected');
			
			if (node) {
				$.webapp.open($.webapp.root + "/admin/site/doc/doc_form_UI.do?id="+node.id+"&pid="+nodetree.id) ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		} else {
	    	var node = $tree.tree('getSelected');
			if(node){
				$.webapp.open($.webapp.root + "/admin/site/doc/doc_form_UI.do?pid="+node.id) ;
			} else {
				alertify.warning("请选择栏目！");
			}
		}
    }
    function del() {
    	
    	var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		} else {
			alertify.warning("请选择一条记录！");
			return false;
		}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.post($.webapp.root+"/admin/site/doc/delete.do", {"ids" : ids.join(',')}, function(result) {
					if (result.status) {
						$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
						alertify.success(result.msg);
						$.easyui.loaded();
					} else {
						alertify.warning(result.msg);
						$.easyui.loaded();
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
    }
    
    function push(id) {
    	$.post($.webapp.root+"/admin/site/doc/doNotNeedAuth_push.do", {"id" : id}, function(result) {
    		if (result.status) {
				$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
				alertify.success(result.msg);
				$.easyui.loaded();
			} else {
				alertify.warning(result.msg);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
    }
    
    </script>
</head>

<body>
	<div class="easyui-layout" data-options="fit:true">
		
		<div data-options="region:'west',split:true" style="width:230px;border-top:none;">
			<div class="easyui-layout" data-options="fit:true"> 
				<div data-options="region:'center',border:false,iconCls:'icon-hamburg-category'" title="栏目列表">
					<div id="tree"></div>
				</div>
			</div>
		</div>
		
		<div data-options="region:'center',border:false">
			<div class="easyui-layout" data-options="fit:true">
			
				<div data-options="region: 'north', split: false, border: true" style="border-top:none;height: 33px;">
	                <div class="easyui-toolbar">
	                    <a onClick="form_edit();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">新增</a>
	                    <a onClick="form_edit('E')" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_save'">编辑</a>
	                    <a onClick="del()" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
	                    <a onClick="$dg.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
	                </div>
	            </div>
				<div data-options="region:'center'">
					<div id="dg"></div>
				</div>
				
			</div>
		</div>
		
	</div>
    
</body>
</html>



